package model.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.bean.User;

public class CheckLoginCustomerDAO extends BaseDAO{

    Connection connection = null;
    public User getUser(String userName, String password) {
        connection = getConnection();
        String sqlCheckLogin = "SELECT * FROM KHACHHANG WHERE TaiKhoan = ? AND MatKhau = ?";
        User user = null;
        if (connection != null) {
            try {
               PreparedStatement pstm = connection.prepareStatement(sqlCheckLogin);
               pstm.setString(1, userName);
               pstm.setString(2, password);
               ResultSet result = pstm.executeQuery();
               if(result.next()){
                   user = new User();
                   user.setID(result.getInt(1));
                   user.setNameUser(result.getString(2));
                   user.setAddress(result.getString(3));
                   user.setSex(result.getBoolean(4));
                   user.setPhoneNumber(result.getString(5));
                   user.setEmail(result.getString(6));
                   user.setBonnusID(result.getInt(9));
                   user.setPassport(result.getString(10));
                   user.setAvatar(result.getString(11));
                   user.setDateOfBirth(result.getDate(12));
               }
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                closeConnection();
            }
        }else {
            // do not something
        }
        return user;
    }
    
}
